--------------------------------------------------------------------------------
--  *  Prog name CBS.adb
--  *  Project name CBS
--  *
--  *  Version 1.0
--  *  Last update 09/09/01
--  *
--  *  Created by Antonio Barros on 09/09/01.
--  *  Copyright (c) 2009 CISTER.
--  *  GNAT modified GNU General Public License
--  *

pragma Task_Dispatching_Policy(EDF_Across_Priorities);

with Ada.Text_IO;
with Constant_Bandwidth_Servers; use Constant_Bandwidth_Servers;
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Real_Time;



procedure CBS is
  CBS : Constant_Bandwidth_Server(1, 50);

  -- APERIODIC TASK ------------------------------------------------------------
  task type Aperiodic_Task is
    entry Release;
  end Aperiodic_Task;

  task body Aperiodic_Task is
    J : Positive := 1;
    Titi : Positive;
  begin
    --Task_Number := Positive(Ada.Task_Identification.Current_Task);
    Ada.Text_IO.Put_Line("Task running...");
    --Ada.Text_IO.Put_Line(Positive'Image(Task_Number));
    CBS.Register;
    Ada.Text_IO.Put_Line("Task registered in CBS...");
    loop
      accept Release;  -- Waits for release order.
      Ada.Text_IO.Put_Line("Job " & Positive'Image(J) & " starting...");
      CBS.Release;  -- Asks the CBS the schedule the job.
      Ada.Text_IO.Put_Line("   -> Permission granted from server...");
      -- Do task work...
      Dot_Loop:
      for I in Integer range 1 .. 80 loop
        Ada.Text_IO.Put(".");
        Burning_Fat_Loop:
                for X in Integer range 1 .. 1000000 loop
          Titi := 22;
        end loop Burning_Fat_Loop;
      end loop Dot_Loop;
      Ada.Text_IO.New_Line;

      Ada.Text_IO.Put("Job " & Positive'Image(J) & " finishing...");
      CBS.Finish;  -- Informs the CBS that the job is done.
      J := J + 1;
    end loop;
  end Aperiodic_Task;
  ------------------------------------------------------------------------------

  T1 : Aperiodic_Task;
  --T2 : Aperiodic_Task;
begin
  -- insert code here...
  Ada.Text_IO.Put_Line("Hello, World again with Ada!");
  loop
    T1.Release;
    delay 2.0;
  end loop;

end CBS;

